package com.atguigu.blog.frontcontroller;

import com.atguigu.blog.client.OssClient;
import com.atguigu.blog.entity.EduBlog;
import com.atguigu.blog.service.EduBlogService;
import com.atguigu.blog.service.OssService;
import com.atguigu.commonutils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/blogservice")
public class IndexController {
    @Autowired
    EduBlogService blogService;
    @Autowired
    OssClient ossClient;
    @Autowired
    OssService ossService;



    /**获取轮播图*/
    @GetMapping("/index/banner")
    public R getBanner(@PathVariable long currentPage) {
        Page page = new Page(currentPage, 4);
        IPage pageData = blogService.page(page, new QueryWrapper<EduBlog>().orderByDesc("created_time"));
        return R.ok().data("pageData", pageData);
    }

    /**
     * 获取最热文章
     */
    @GetMapping("/index/hot")
    public R getHotBlog(@PathVariable long currentPage) {
        Page page = new Page(currentPage, 4);
        IPage pageData = blogService.page(page, new QueryWrapper<EduBlog>().orderByDesc("created_time"));
        return R.ok().data("pageData", pageData);
    }

    /**
     * 获取最新文章
     */
    @GetMapping("/index/latest")
    public R getLatestBlog(@PathVariable long currentPage) {
        Page page = new Page(currentPage, 4);
        IPage pageData = blogService.page(page, new QueryWrapper<EduBlog>().orderByDesc("created_time"));
        return R.ok().data("pageData", pageData);
    }
}
